package com.wdb007.venus.wss.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wdb007.venus.wss.channelgroup.BookCaseChannelGroups;
import com.wdb007.venus.wss.service.WebSocketServerService;

import io.netty.channel.ChannelHandlerContext;

@Service("bookCaseMaintenanceUnlockService")
public class BookCaseMaintenanceUnlockService implements WebSocketServerService {

	private static Logger logger = LoggerFactory.getLogger(BookCaseMaintenanceUnlockService.class);
	
	@Override
	public String doService(ChannelHandlerContext ctx, String request) throws Exception {
		JSONObject jsonObj = JSON.parseObject(request);
		logger.info("BookCaseReq 接收websocket响应信息: {}", jsonObj.toJSONString());
		String action = jsonObj.getString("action");
		if("maintenance_unlock_req".equals(action)) {
			String bookCaseId = (String) jsonObj.remove("bookCaseId");
			BookCaseChannelGroups.broadcast(bookCaseId, jsonObj.toJSONString());
		}
		
		return null;
	}

}
